const isImage = (url) =>{
  const imageExtensions = ['.jpg', '.jpeg', '.png', '.gif', '.bmp','.webp']
  const ext = url.substring(url.lastIndexOf('.')).toLowerCase()
  return imageExtensions.includes(ext)
}

const isVideo = (url) =>{
  const imageExtensions = ['.mp4', '.wav', '.mov', '.flv']
  const ext = url.substring(url.lastIndexOf('.')).toLowerCase()
  return imageExtensions.includes(ext)
}

const isAdmin = () => {
  if (parseInt(sessionStorage.getItem('role')) >= 9) {
    return true
  }
  return false
}

const isLeader = () => {
  if (parseInt(sessionStorage.getItem('role')) > 9) {
    return true
  }
  return false
}

//给备注里的链接自动加上超链接
const addHyperlinks = (text) =>{
  // 匹配链接的正则表达式
  let urlRegex = /(https?:\/\/[^\s]+)/g;

  // 使用 replace 方法将匹配到的链接替换为带有超链接的文本
  return text.replace(urlRegex, function(url) {
      return '<a href="' + url + '" target="_blank">' + url + '</a>';
  });
}

export default{
  isImage,isVideo,isAdmin,isLeader,addHyperlinks
}